package cq.com.cn.servlet;

import com.google.gson.JsonObject;
import cq.com.cn.model.UserModel;
import cq.com.cn.service.UserService;
import cq.com.cn.utils.AjaxUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
@WebServlet("/check/findEmail.do")
public class CheckEmailServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取书籍类型
        String email=req.getParameter("email");
        //调用业务层
        UserService userService=new UserService();
        UserModel userModel = userService.queryUserByEmail(email);
        //返回数据给前端
        JsonObject obj=new JsonObject();
        if(userModel==null) {
            obj.addProperty("rs", true);
        } else {
            obj.addProperty("rs", false);
        }
        AjaxUtils.ajaxHtml(obj.toString(),resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
